import { Body, Controller, Get, Post, UseGuards, Request } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { User } from "../../user/entities/user.entity";
import { JwtAuthGuard } from "../guard/jwt-auth.guard";
import { LocalAuthGuard } from "../guard/local-auth.guard";
import { AuthService } from "../service/auth.service";
@ApiTags('auth - 登录')
@Controller('auth')
export class AuthController {
    constructor(
        private readonly authService: AuthService
    ) { }

    @UseGuards(LocalAuthGuard)
    @Post('/login')
    @ApiOperation({
        summary: "登录",
    })
    async login(@Body() user: User) {
        // console.log(req);
        return this.authService.login(user);
    }

    @UseGuards(JwtAuthGuard)
    @Get('profile')
    @ApiOperation({
        summary: "测试jwt是否生效",
    })
    getProfile(@Request() req) {
        // console.log(req.headers['token']);
        // const { userId } = req.headers['token'];
        console.log(req)
        return req.user;
    }



}

